package com.约瑟夫环;

public class ysfh {
    public static void main(String[] args) {
        huangou huan = new huangou();
        huan.add(125);
       // huan.show();
        huan.ysf(1,20,125);
        huan.show();
    }
}
class huangou{
    private boy head = null;
    public void add(int num){
        if(num<1){
            System.out.println("你输入的值不对");
            return;
        }
        boy hhh=null;
        for (int i = 1; i <= num; i++) {
            boy man = new boy(i);
            if(i==1){
                head=man;
                head.setNext(head);
                hhh=head;
            }
            else {
                hhh.setNext(man);
                man.setNext(head);
                hhh=man;
            }
        }
    }
    public void show(){
        boy hhh=head;
        if(head==null){
            System.out.println("链表为空");
        }
       while (true){
           System.out.printf("小孩的编号 %d\n",hhh.getNo());
           if(hhh.getNext()==head){
               break;
           }
           hhh=hhh.getNext();
       }
    }
    public void ysf(int star,int cout,int num){

        if(head==null || star<1 || star>num){
            System.out.println("数据错误");
            return;
        }
        System.out.println("11111");
        boy help=head;

        while (true) {
            if(help.getNext()==head){
                break;
            }
            help=help.getNext();
        }

            for (int ij = 0; ij < star-1; ij++) {
                head=head.getNext();
                help=head.getNext();
            }

         while (true){
             if(help==head){

                 break;
             }
             for (int ijh = 0; ijh <cout-1 ; ijh++) {
                 head=head.getNext();
                 help=help.getNext();
             }
             System.out.println("小孩；"+head.getNo());
             head=head.getNext();
             help.setNext(head);
         }
        System.out.println(head.getNo());

    }
}
class boy{
    private int no;
    private boy next;

    public boy(int no) {
        this.no = no;
    }

    public void setNext(boy next) {
        this.next = next;
    }

    public boy getNext() {
        return next;
    }

    public void setNo(int no) {
        this.no = no;
    }

    public int getNo() {
        return no;
    }
}